package com.wx.business.course.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.eachonline.mapper.GenericMapper;
import com.eachonline.service.GenericServiceImpl;
import com.eachonline.util.RedisHelper;
import com.wx.business.course.IxbCourseCategoryService;
import com.wx.dao.mapper.IxbCourseCatagroyMapper;
import com.wx.model.IxbCourseCatagroy;
import com.wx.model.IxbCourseCatagroyExample;
@Service("ixbCoursecCategoryService")
public class IxbCourseCategoryServiceImpl extends GenericServiceImpl<IxbCourseCatagroy, IxbCourseCatagroyExample, String> implements IxbCourseCategoryService  {

	private static final  Logger logger =Logger.getLogger(IxbCourseCategoryService.class);

	@Resource
	private IxbCourseCatagroyMapper ixbCourseCatagroyMapper;
	
	@Override
	protected GenericMapper<IxbCourseCatagroy, IxbCourseCatagroyExample, String> getGenericMapper() {
		return ixbCourseCatagroyMapper;
	}

	@Override
	public String getCourseCategoryName(String categoryCode) {
		// TODO Auto-generated method stub
		return getCourseCategory(categoryCode).getCatagroyName();
	}

	@Override
	public IxbCourseCatagroy getCourseCategory(String code) {
		// TODO Auto-generated method stub
		IxbCourseCatagroy category=(IxbCourseCatagroy) RedisHelper.getObject(code);
		
		if(category!=null)
			return category;
			
	
		IxbCourseCatagroyExample  categoryCtr=new IxbCourseCatagroyExample();
		categoryCtr.createCriteria().andCodeEqualTo(code);
	    List<IxbCourseCatagroy> list=ixbCourseCatagroyMapper.selectByExample(categoryCtr);
	    if(list==null||list.isEmpty())
	    {
	    	return null;
	    }
	    category=list.get(0);
	    RedisHelper.set(code, category);
	    return category;
		
	}

	
}
